import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.time.DateUtils;

import java.text.ParseException;
import java.util.Map;

public class test {

    public static void main(String[] args) throws Exception {
//        SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss:SSS");
//        SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        System.out.println(Timestamp.valueOf(format2.format(format1.parse("2021-02-06 10:00:00:996"))).getTime());
//        System.out.println(format1.parse("2021-02-06 10:00:00:996").getTime());
//        System.out.println( DateUtils.parseDate("2021-02-06 10:00:00:996","yyyy-MM-dd HH:mm:ss:SSS").getTime());
//        System.out.println(Timestamp.valueOf("2021-02-06 10:00:00:996".substring(0,19)));
//        System.out.println("2021-02-06 10:00:00:996".substring(0,19));
//        String DEFAULT_FORMAT_STRING = "yyyy/MM/dd/HH";
/*        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Preconditions.checkNotNull("yyyy/MM/dd/HH"))
        .withZone( Preconditions.checkNotNull(ZoneId.systemDefault()));

        String event ="{\"operateStatus\":\"0\",\"offset\":25650723,\"data\":\"{\\\"sourceid\\\":\\\"3\\\",\\\"request\\\":{\\\"sourceid\\\":\\\"3\\\",\\\"appType\\\":\\\"4\\\",\\\"msgid\\\":\\\"7f053979-0841-4ef2-a1ed-c7b9628b20e3\\\",\\\"type\\\":\\\"2\\\",\\\"version\\\":\\\"1.0\\\",\\\"account\\\":\\\"15907743325\\\"},\\\"costtime\\\":45,\\\"response\\\":{\\\"data\\\":{\\\"simfunction\\\":\\\"0\\\",\\\"flag\\\":\\\"7\\\",\\\"provCode\\\":\\\"771\\\",\\\"mobileNumber\\\":\\\"15907743325\\\",\\\"roleId\\\":\\\"0\\\",\\\"passid\\\":\\\"972845147\\\",\\\"ha1Password\\\":\\\"\\\",\\\"upgradeSourceFlag\\\":\\\"3\\\",\\\"userid\\\":\\\"a1118563205\\\",\\\"sysPassid\\\":\\\"0\\\",\\\"pwdGrade\\\":\\\"0\\\",\\\"areaCode\\\":\\\"0774\\\",\\\"useFlag\\\":\\\"6\\\",\\\"safeLevel\\\":\\\"\\\",\\\"createTime\\\":\\\"*****\\\",\\\"serviceStatus\\\":\\\"0\\\",\\\"mobileCloseFlag\\\":\\\"0\\\",\\\"status\\\":\\\"0\\\"},\\\"resultCode\\\":2000}}\",\"responseTime\":\"2021-03-11 17:00:31:366\",\"input_type\":\"log\",\"operateType\":\"US0004\",\"channel\":\"NULL\",\"source\":\"/data/log/microus/microus02/athena.log\",\"sessionId\":\"NULL\",\"message\":\"2021-03-11 17:00:31:366|1|15907743325|US0004|0|NULL|NULL|2021-03-11 17:00:31:321|2021-03-11 17:00:31:366|NULL|10.153.75.106|10.153.75.155:9011|{\\\"sourceid\\\":\\\"3\\\",\\\"request\\\":{\\\"sourceid\\\":\\\"3\\\",\\\"appType\\\":\\\"4\\\",\\\"msgid\\\":\\\"7f053979-0841-4ef2-a1ed-c7b9628b20e3\\\",\\\"type\\\":\\\"2\\\",\\\"version\\\":\\\"1.0\\\",\\\"account\\\":\\\"15907743325\\\"},\\\"costtime\\\":45,\\\"response\\\":{\\\"data\\\":{\\\"simfunction\\\":\\\"0\\\",\\\"flag\\\":\\\"7\\\",\\\"provCode\\\":\\\"771\\\",\\\"mobileNumber\\\":\\\"15907743325\\\",\\\"roleId\\\":\\\"0\\\",\\\"passid\\\":\\\"972845147\\\",\\\"ha1Password\\\":\\\"\\\",\\\"upgradeSourceFlag\\\":\\\"3\\\",\\\"userid\\\":\\\"a1118563205\\\",\\\"sysPassid\\\":\\\"0\\\",\\\"pwdGrade\\\":\\\"0\\\",\\\"areaCode\\\":\\\"0774\\\",\\\"useFlag\\\":\\\"6\\\",\\\"safeLevel\\\":\\\"\\\",\\\"createTime\\\":\\\"*****\\\",\\\"serviceStatus\\\":\\\"0\\\",\\\"mobileCloseFlag\\\":\\\"0\\\",\\\"status\\\":\\\"0\\\"},\\\"resultCode\\\":2000}}\",\"type\":\"micro-us\",\"transactionId\":\"NULL\",\"logTime\":\"2021-03-11 17:00:31:366\",\"tags\":[\"groked\"],\"requestTime\":\"2021-03-11 17:00:31:321\",\"@timestamp\":\"2021-03-11T09:00:31.366Z\",\"sourceIp\":\"10.153.75.106\",\"serverAddr\":\"10.153.75.155:9011\",\"beat\":{\"hostname\":\"microserv-umus03\",\"name\":\"10.153.75.155\",\"version\":\"5.5.2\"},\"@version\":\"1\",\"userType\":\"1\",\"user\":\"15907743325\"}";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
        System.out.println( "SimpleDateFormat 类的默认时区：" + simpleDateFormat.getTimeZone().getID() );
        simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
        String even_time = (String)((Map) JSON.parse(event)).getOrDefault("@timestamp","1970-01-01T00:00:00.000Z");
        System.out.println(simpleDateFormat.parse(even_time));
        String partitionName = dateTimeFormatter.format(Instant.ofEpochMilli(simpleDateFormat.parse(even_time).getTime()));
        System.out.println(partitionName);*/
//        Map valueMap = (Map)JSON.parse(event);
//        System.out.println(valueMap.values());
//        Collection values = valueMap.values();
//        String[] s = new String[50];
//        values.toArray(s);
//        System.out.println(s);
//        List<String> l = new ArrayList<String>();
//        l.add("ssdsa");
//        l.add("zzxxc");
//        System.out.println(String.join("|",valueMap.values()));
//        System.out.println(StringUtil.join("|",valueMap.values()));
//        System.out.println(org.apache.commons.lang3.StringUtils.join(valueMap.values(),"|"));

        String data = "2,3,4"; // 加密和解密测试数据
        String password = "dnAnalysis01pwd"; // 密钥密码
        String isnull = null;

        String result = "123|2021-04-13|15875308654|2021-04-13|NULL|789|2000-01-01 00:00:00:001|2021-04-13 00:00:00:001";

        Map valueMap = (Map) JSON.parse("{\n" +
                "    \"offset\":0,\n" +
                "    \"user_enterprise_id\":\"95880\",\n" +
                "    \"pod_ip\":\"172.20.30.135\",\n" +
                "    \"prospector\":{\n" +
                "        \"type\":\"log\"\n" +
                "    },\n" +
                "    \"source\":\"/logdata/appTracking.log\",\n" +
                "    \"message\":\"{\\\"event\\\":\\\"work_button_click\\\",\\\"user_phone_number\\\":\\\"13531189754\\\",\\\"click_time\\\":\\\"2021-07-16 00:23:44\\\",\\\"user_enterprise_id\\\":\\\"95880\\\",\\\"application_click\\\":\\\"更多工具\\\",\\\"user_enterprise_name\\\":\\\"政企轻办公测试企业\\\"}\",\n" +
                "    \"type\":\"origin-appTracking\",\n" +
                "    \"pod_name\":\"andworkdata-859756f658-zfdjg\",\n" +
                "    \"tags\":[\n" +
                "        \"north-yunqixin\"\n" +
                "    ],\n" +
                "    \"input\":{\n" +
                "        \"type\":\"log\"\n" +
                "    },\n" +
                "    \"log_type\":\"origin-andworkdata\",\n" +
                "    \"@timestamp\":\"2021-07-15T16:23:54.024Z\",\n" +
                "    \"user_phone_number\":\"13531189754\",\n" +
                "    \"click_time\":\"2021-07-16 00:23:44\",\n" +
                "    \"beat\":{\n" +
                "        \"hostname\":\"andworkdata-859756f658-zfdjg\",\n" +
                "        \"name\":\"andworkdata-859756f658-zfdjg\",\n" +
                "        \"version\":\"6.3.2\"\n" +
                "    },\n" +
                "    \"host\":{\n" +
                "        \"name\":\"andworkdata-859756f658-zfdjg\"\n" +
                "    },\n" +
                "    \"@version\":\"1\",\n" +
                "    \"application_click\":\"更多工具\",\n" +
                "    \"event\":\"work_button_click\",\n" +
                "    \"user_enterprise_name\":\"政企轻办公测试企业\"\n" +
                "}");
        /*if (valueMap != null) {
            String val = (String) valueMap.getOrDefault("type", "lxl");
            System.out.println(val);
        }
        try {
            if (data != null) {
                String encryptedData = CipherPBEMd5Des.encrypt(data, password);//根据密钥密码加密数据
                String encryptedData2 = CipherPBEMd5Des.encrypt(encryptedData, password);//根据密钥密码加密数据

                System.out.println(CipherPBEMd5Des.encrypt("", password));
                System.out.println("data:" + data + ", DES加密：" + encryptedData);
                System.out.println("data:" + encryptedData + ", DES加密：" + encryptedData2);
                String dencryptData = CipherPBEMd5Des.decrypt(encryptedData2, password);//根据密钥密码解密数据
                String dencryptData2 = CipherPBEMd5Des.decrypt(encryptedData, password);//根据密钥密码解密数据
                System.out.println("加密数据:" + encryptedData2 + ", DES解密：" + dencryptData);
                System.out.println("加密数据:" + encryptedData + ", DES解密：" + dencryptData2);

                StringBuffer b = new StringBuffer(data).insert(0, "\\|").append("\\|");
                StringBuffer enData = new StringBuffer(encryptedData).insert(0, "\\|").append("\\|");

                System.out.println(result.replace(b.toString(), enData.toString()));


            } else {
                throw new Exception("11111111");
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("异常信息");
        }*/
 /*       String s = result.split("\\|")[2];
        System.out.println(s);

        String jsonStr = "{\"logtime\" : \"0\" ,\"usertype\"    : \"SUCCESS\",\"user\"    : \"李晓亮\",\"sessionid\"    : \"123456789\",\"requesttime\"    : \"1615863103\",\"responsetime\"    : \"1615863322\",\"@timestamp\":\"2021-04-13 00:00:00:001\"}";
        String jsonNull = "{}";
        Map<String, String> parse = (Map) JSON.parse(jsonStr);
        Map<String, String> parse1 = (Map<String, String>) JSON.parse(jsonNull);
        Collection<String> values = parse.values();

        List<String> valuesList = new ArrayList<String>(parse.values());
        System.out.println(valuesList);
        System.out.println(values);
        System.out.println(StringUtils.join(parse.values(), "|"));

        System.out.println("user:" + parse.get("user"));
        String splitF = "\\|";

        String[] split = data.split(",");
        System.out.println(CipherPBEMd5Des.encrypt("123", "zxc@._875"));

        for (String s1 : split) {
            System.out.println("----------------" + result.split(splitF)[Integer.valueOf(s1)]);

            String pre_data = result.split(splitF)[Integer.valueOf(s1)];


            if (pre_data != "null" && !pre_data.equals("NULL")) {
                String decrypt = CipherPBEMd5Des.decrypt("tOdTikjurYI=", "zxc@._875");
                String res_data = CipherPBEMd5Des.encrypt(pre_data, decrypt);//根据密钥密码加密数据

                System.out.println("pre_data:" + pre_data + ", DES加密：" + res_data);
                String realdata  = CipherPBEMd5Des.decrypt(res_data, decrypt);
                System.out.println("res_data:" + res_data + ", DES解密：" + realdata);


                StringBuffer b = new StringBuffer(pre_data).insert(0, splitF).append(splitF);
                StringBuffer enData = new StringBuffer(res_data).insert(0, splitF).append(splitF);
                result = result.replaceFirst(b.toString(), enData.toString());
            }
            System.out.println(result);
        }
*/
        //System.out.println(valueMap.get("offset").toString());
        //System.out.println(CipherPBEMd5Des.decrypt("123", "zxc@._875"));//根据密钥密码加密数据
        //System.out.println(CipherPBEMd5Des.encrypt(valueMap.get("beat").toString(), "zxc@._875"));//根据密钥密码加密数据
        //System.out.println(isnull.isEmpty());
        String b = "yzapi,yzsms|tyrz_yz_analysis";
        String a =null;
        if (!a.isEmpty()){
            System.out.println(123);
        }
        System.out.println(b.split("\\|")[1]);
    }

    private static Long getEventTime(String element) throws ParseException {
        return DateUtils.parseDate("2021-02-06 10:00:00:996", "yyyy-MM-dd HH:mm:ss:SSS").getTime();
    }
}

